<?php
/**
 * Created by 784855684@qq.com.
 * Link: https://github.com/lichtung/wshore
 * User: linzh
 * Date: 6/30/17
 * Time: 3:02 PM
 */
declare(strict_types=1);


namespace application\module\admin\addon\model;


use wshore\core\ActiveRecord;

abstract class AddonModel extends ActiveRecord
{

    public function __construct($id = null)
    {
        parent::__construct($id);
    }

    protected function tablePrefix()
    {
        return 'ws_';
    }

    /**
     * 创建语句
     * @return string
     */
    abstract protected function struct(): string;

    /**
     * 安装模型
     * @return void
     */
    public function install()
    {
        $tableName = $this->tablePrefix() . $this->tableName();
        $struct = $this->struct();
        $sql = "CREATE TABLE IF NOT EXISTS `{$tableName}` ( {$struct} ) 
                ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        $this->exec($sql);
    }
}